package info.wangyuan.agent.config;

import info.wangyuan.agent.interceptor.CertificationInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨域配置
 *
 * @author Albert
 * @since 2025-07-23 12:21:35
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    private final CertificationInterceptor certificationInterceptor;

    public WebConfig(CertificationInterceptor certificationInterceptor) {
        this.certificationInterceptor = certificationInterceptor;
    }

    /**
     * 跨域设置
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedHeaders("*")
                .allowedMethods("*")
                .allowedOrigins("*")
                .allowCredentials(false)
                .maxAge(3600L);
    }

    /**
     * 拦截器配置
     */
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(certificationInterceptor)
//                .addPathPatterns("/**")
//                .excludePathPatterns(
//                        "/wx/login",
//                        "/wx/info/code",
//                        "/rag/search/welcomeMsg",
//                        "/rag/search/getCurrentModel",
//                        "/qrcode/page/**"
//                )
//                .order(0);
//    }
}
